package com.yyb.utils;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * : [得到servlet的相关作用域对象]
 * 
 * 
 */
public class ServletUtils {

    /**
     * 得到request
     */
    public static HttpServletRequest getRequest(){
        return getRequestAttributes().getRequest();
    }

    /**
     * 得到Session
     */
    public static HttpSession getSession(){
        return getRequestAttributes().getRequest().getSession();
    }

    /**
     * 得到response
     */
    public static HttpServletResponse getResponse(){
        return getRequestAttributes().getResponse();
    }
    /**
     * 得到ServletRequestAttributes
     */
    public static ServletRequestAttributes getRequestAttributes(){
        RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
        return (ServletRequestAttributes) attributes;
    }


}
